package year2019.month12;

//冒泡排序
public class BubbleSort {

    public static void main(String[] args){
        int[] arr = {5,2,49,10,12,1,9,20,3,0,16,9,45};

        int[] arrSort = sort(arr);
        for (int a : arrSort){
            System.out.print(a+"\t");
        }
    }

    public static int[] sort(int[] arr){
        int[] arrSort = arr.clone();
        for (int i=arrSort.length-1; i>=0; i--){
            for (int k=1; k<=i; k++){
                int pre = arrSort[k-1];
                int curr = arrSort[k];
                if (curr<pre){
                    arrSort[k-1] = curr;
                    arrSort[k] = pre;
                }
            }
        }
        return arrSort;
    }

}
